﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;
using System.Collections.Generic;
namespace Login
{
    public class LoginPlayerCreate : Fsm.FsmStateMonoBase<LoginState>
    {
            LoginManager manager = null;
        public LoginPlayerCreate(LoginState state, LoginManager ctrl) : base(state, ctrl) { manager = ctrl; }

        public override void Enter()
        {
            PlayerCreate();
        }
        void PlayerCreate() 
        {
            CSPlayerCreate msg = new CSPlayerCreate();
            msg.playerName = manager.nickNameStr;
            msg.heroId = "hero_001";//暫時寫死
            msg.gender = 0;//暂时写死
            Debug.Log("PlayerCreate playerName = " + manager.nickNameStr);
            NetAPI.SendHttp(OpDefine.CSPlayerCreate, msg, PlayerCreateCallBack);
        }
        void PlayerCreateCallBack(NetWork.Packets.Packet packet, bool bSuccess) {
            if (bSuccess)
            {
                SCPlayerCreate msg = packet.kBody as SCPlayerCreate;
                if (msg != null)
                {
                    manager.SwitchState(LoginState.PlayerLogin);
                }
            }
        }
    }
}
